package com.zhiyou100.action;

import com.zhiyou100.entity.Student;
import com.zhiyou100.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author yang
 * @className StudentAction
 * @packageName com.zhiyou100.action
 * @Description TODO 学生 action
 * @date 2020-08-22 15:36
 */
@Controller
@RequestMapping("/student")
public class StudentAction {

    private StudentService StudentDao;

    @Autowired
    public void setStudentDao(StudentService studentDao) {
        StudentDao = studentDao;
    }


    @RequestMapping("/getAll.action")
    public String getAll(HttpServletRequest request) {
        final List<Student> all = StudentDao.getAll();
        request.setAttribute("all", all);
        return "index";
    }

    @RequestMapping("/addOne.action")
    public String addOne(Student student, HttpServletRequest request) {
        StudentDao.addOne(student);
        return "index";
    }

    @RequestMapping("/delOne.action")
    public String delOne(Integer sid) {
        StudentDao.delOneBySid(sid);
        return "index";
    }

    @RequestMapping("/updateOne.action")
    public String updateOne(Student student) {
        StudentDao.updateOne(student);
        return "index";
    }

    @RequestMapping("/getOneBySid.action")
    public String getOneBySid(Integer sid, HttpServletRequest request) {
        final Student oneBySid = StudentDao.getOneBySid(sid);
        request.setAttribute("student", oneBySid);
        return "index";
    }
}
